<?php
/**
 * Created by PhpStorm.
 * User: HJJ
 * Date: 2022-11-10
 * Time: 10:22:35
 * Info:
 */

namespace app\api\controller;
use app\common\model\tabar as tabarModel;
use app\common\model\banner as bannerModel;
use app\common\model\bannerType as bannerTypeModel;
use app\common\model\notice as noticeModel;
use app\common\model\article as articleModel;

use think\facade\Db;

class WechatController extends BaseController
{
    // 首页数据
    public function index()
    {
        $tabList = tabarModel::order('sort_order asc, id desc')->select(); // 栏目
        $tid = bannerTypeModel::where('name', '首页轮播图')->value('tid');
        $swiperList = bannerModel::order('listorder asc, id desc')->limit(5)->where('typeid', $tid)->select(); // 轮播图
        $noticeList = noticeModel::order('sorts asc, id desc')->limit(5)->select(); // 栏目
        $recentPolicyList = articleModel::order('create_time desc, weight asc, id desc')->limit(3)->select(); // 近期政策
        $data = array(
          'wx_name' => get_config('wx_name'),
          'wx_logo' => get_config('wx_logo'),
          'tabList' => $tabList,
          'swiperList' => $swiperList,
          'noticeList' => $noticeList,
          'recentPolicyList' => $recentPolicyList,
        );
        $this->success(200, $data);
    }

    // 文章列表
    public function getArticleList()
    {
        $page  = (int)$this->request->param('page', 1);
        $limit = (int)$this->request->param('limit', 10);
        $type_md = (int)$this->request->param('type_md', 1);
        $first = ($page - 1) * $limit;
        $count = articleModel::where('type_md', $type_md)->count();
        $list  = articleModel::field('id, title, image, click, create_time')->limit($first, $limit)->order('weight asc, id desc')->where('type_md', $type_md)->select();
        $this->success(200, array(
            'count' => $count,
            'data' => $list,
        ));
    }

    public function test()
    {
        $this->success('这个是需要验证的哦');
    }

}